const app = getApp()
var httpClient = require("../../../utils/HttpClient.js");
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    detail: {},
    elevatorInfo:{},
    customerInfo:{},
    innerid:null,
  },

  getElevatorInfo: function (WorkOrderNumber, ElevatorNumber) {
    httpClient.superAjax({
      isWebService: true,
      url: 'F0905Service.asmx/getDetailInfoByOrderElevatorNumberMin',
      data: {
        workordernumber: WorkOrderNumber,
        elevatornumber: ElevatorNumber,
        _this: this
      },
      success: function (data) {
        data[0].ElevatorDealTime = data[0].ElevatorDealTime.substr(0, 19).replace('T', ' ');
        this.data._this.setData({
          "elevatorInfo": data[0]
        });
      }
    })
  },

  getCustomerInfo: function (CustomerNumber) {
    httpClient.superAjax({
      isWebService: true,
      url: 'CustomerService.asmx/getCustomerInfoByNumberMin',
      data: {
        CustomerNumber: CustomerNumber,
        _this: this
      },
      success: function (data) {
        this.data._this.setData({
          "customerInfo": data[0]
        });
      }
    })
  },

  onLoad: function(option) {
    this.setData({ "innerid":option.innerid});
    httpClient.superAjax({
      isWebService: true,
      url: 'F0905Service.asmx/getManatenceGeneralInfoByInnerIdMin',
      data: {
        innerid: option.innerid,
        _this: this
      },
      success: function (data) {
        var d = data.F0905[0];
        d.WorkOrderDealTime = d.WorkOrderDealTime.substr(0, 19).replace('T', ' ');
        d.NeedCompleteTime = d.NeedCompleteTime.substr(0, 19).replace('T', ' ');
        d.Location = '经纬度：' + d.Location;
        d.OrderStatus = d.OrderStatus == 30 ? '完成' : '已确认';

        var t = "";
        data.F0905x2.forEach(function (value, index, arrSelf){
          t += "," + value.EmployeeName;
        })
        d.F0905x2=t.substr(1);

        this.data._this.setData({
          "detail": d
        });

        console.log(d);

        this.data._this.getElevatorInfo(d.WorkOrderNumber, d.ElevatorNumber);
        this.data._this.getCustomerInfo(d.CustomerNumber);

      }
    })
  },

 
  submit: function(e) {
    httpClient.superAjax({
      isWebService: true,
      showWarnAlert: true,
      operateType: '提交',
      url: 'CommonMethods.asmx/UploadConfirmOrderMin',
      data: {
        innerid: this.data.innerid,
        confirmtype: "MAINTAIN", //困人救援:TREAT,故障保修: URGENT ,保养工单:MAINTAIN 
        filename: "",
        note: "",
        image: "",
        filetype: "",
        _this: this
      },
      success: function(data) {
        var result = '操作失败';
        if (data.length > 0 && data[0].Code == 200) {
          result = '操作成功';
        }
        wx.showToast({
          icon: 'none',
          title: result,
          success: function() {
            setTimeout(function() {
              wx.navigateBack({
                delta: 1
              })
            }, 700) //延迟时间 
          }
        })
      }
    })
  }
})